using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using EIA.Basic.Model;
using EIA.Basic.DAL;

namespace EIA.Basic.BLL
{
    public class TPositionBlp : ITPositionBlp
    {
        ITPositionDao _TPositionDao = null;
        public TPositionBlp()
        {
            _TPositionDao = X.DaoFactory.Create<ITPositionDao>();
        }

        public int Insert(TPosition o)
        {
            object r = _TPositionDao.Insert(o);
			return r is int ? (int)r : 0;
        }

        public IList<int> InsertList(IList<TPosition> lst)
        {
            _TPositionDao.DASession.BeginTransaction();
            try
            {
                IList<int> keys = new List<int>();
                foreach (TPosition o in lst)
                {
                    object r = _TPositionDao.Insert(o);
                    keys.Add(r is int ? (int)r : 0);
                }
                _TPositionDao.DASession.CommitTransaction();
                return keys;
            }
            catch
            {
                _TPositionDao.DASession.RollbackTransaction();
                throw;
            }
        }

        public bool Update(TPosition o)
        {
            return _TPositionDao.Update(o);
        }

		public bool UpdateChanged(IDictionary props)
		{
			return _TPositionDao.Update(props);
		}

        public bool UpdateList(IList<TPosition> lst)
        {
            _TPositionDao.DASession.BeginTransaction();
            try
            {
                foreach (TPosition o in lst)
                {
                    if (!_TPositionDao.Update(o))
                    {
                        _TPositionDao.DASession.RollbackTransaction();
                        return false;
                    }
                }
                _TPositionDao.DASession.CommitTransaction();
                return true;
            }
            catch
            {
                _TPositionDao.DASession.RollbackTransaction();
                throw;
            }
        }

        public bool Delete(int o_id)
        {
            return _TPositionDao.Delete(o_id) > 0;
        }

        public bool DeleteList(IList<TPosition> lst)
        {
            _TPositionDao.DASession.BeginTransaction();
            try
            {
                foreach (TPosition o in lst)
                {
                    if (_TPositionDao.Delete(o) != 1)
                    {
                        _TPositionDao.DASession.RollbackTransaction();
                        return false;
                    }
                }
                _TPositionDao.DASession.CommitTransaction();
                return true;
            }
            catch
            {
                _TPositionDao.DASession.RollbackTransaction();
                throw;
            }
        }
		
		public int Count(IDictionary con)
		{
			return _TPositionDao.Count(con);
		}

        public IList<TPosition> List(IDictionary con, int pagesize, int page)
        {
            return _TPositionDao.List(con, pagesize, page);
        }
		
        public IList<TPosition> ListAll()
		{
			return _TPositionDao.List(null);
		}

    }
}